load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target")
load("@fbcode_macros//build_defs:cpp_binary.bzl", "cpp_binary")
load("@fbcode_macros//build_defs:cpp_unittest.bzl", "cpp_unittest")
load("@fbcode_macros//build_defs:custom_unittest.bzl", "custom_unittest")
load("@fbsource//tools/build_defs:fb_native_wrapper.bzl", "fb_native")
load("@fbsource//tools/build_defs/dirsync:fb_dirsync_cpp_library.bzl", "fb_dirsync_cpp_library")
load("../../defs.bzl", "folly_xplat_library")

oncall("fbcode_entropy_wardens_folly")

fbcode_target(
    _kind = cpp_unittest,
    name = "async_stack_test",
    srcs = ["AsyncStackTest.cpp"],
    deps = [
        "//folly/portability:gmock",
        "//folly/portability:gtest",
        "//folly/tracing:async_stack",
    ],
    external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "static_tracepoint_test",
    srcs = ["StaticTracepointTest.cpp"],
    extract_helper_lib = False,
    labels = ["oss-broken"],
    deps = [
        "fbsource//third-party/fmt:fmt",
        ":static_tracepoint_test_module",
        "//folly:conv",
        "//folly:format",
        "//folly:random",
        "//folly:string",
        "//folly:subprocess",
        "//folly/debugging/symbolizer/detail:debug",
        "//folly/lang:bits",
        "//folly/portability:filesystem",
        "//folly/portability:gtest",
        "//folly/portability:unistd",
        "//folly/tracing:static_tracepoint",
    ],
)

fb_dirsync_cpp_library(
    name = "static_tracepoint_test_module",
    srcs = [
        "StaticTracepointTestModule.cpp",
    ],
    headers = [
        "StaticTracepointTestModule.h",
    ],
    xplat_impl = folly_xplat_library,
    deps = [
        "//folly/tracing:static_tracepoint",
    ],
)

fb_native.filegroup(
    name = "static_tracepoint_section_test_lds",
    srcs = ["StaticTracepointSectionTest.lds"],
)

fbcode_target(
    _kind = cpp_binary,
    name = "static_tracepoint_section_test_bin",
    srcs = ["StaticTracepointSectionTest.cpp"],
    headers = [],
    linker_flags = [
        "--gc-sections",
        "-T",
        "$(location :static_tracepoint_section_test_lds)/StaticTracepointSectionTest.lds",
    ],
    target_compatible_with = ["fbcode//opensource/macros:broken-in-oss"],
    deps = [
        "//folly/debugging/symbolizer:elf",
        "//folly/tracing:static_tracepoint",
    ],
)

fbcode_target(
    _kind = custom_unittest,
    name = "static_tracepoint_section_test",
    command = ["$(location :static_tracepoint_section_test_bin)"],
    type = "simple",
)
